import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
  firstPage: '/home',
  isUlian: false,
  agencyId: 1,
  userInfo: {},
  companyInfos: [],
  companyColors: [],
  govAgencyList: [],
  companNames: [],
  btnMenuIds: [],
  colors: [],
  splitMapColors: {other: '#fddf01'},
  /*colors: [
   {
   enterpriseName: "摩拜",
   enterpriseId: 13,
   enterpriseNo: "075501",
   color: "#f25b4a",
   mapCount: 0,
   count: 0
   }, {
   enterpriseName: "ofo",
   enterpriseId: 14,
   enterpriseNo: "075502",
   color: "#fddf01",
   mapCount: 0,
   count: 0
   }, {
   enterpriseName: "ubike",
   enterpriseId: 15,
   enterpriseNo: "075503",
   color: "green",
   mapCount: 0,
   count: 0
   },
   {
   enterpriseName: "赳赳",
   enterpriseId: 313,
   enterpriseNo: "075504",
   color: "#9f52d4",
   mapCount: 0,
   count: 0
   }, {
   enterpriseName: "一步",
   enterpriseId: 312,
   enterpriseNo: "075505",
   color: "blue",
   mapCount: 0,
   count: 0
   },{
   enterpriseName: "青桔",
   enterpriseId: 12,
   enterpriseNo: "075511",
   color: "blue",
   mapCount: 0,
   count: 0
   }
   ],*/
  districtData: [],
  pickerOptions0: {
    disabledDate(time) {
      return time.getTime() > Date.now()
    },
    shortcuts: [{
      text: '今天',
      onClick(picker) {
        picker.$emit('pick', new Date())
      }
    }, {
      text: '昨天',
      onClick(picker) {
        const date = new Date()
        date.setTime(date.getTime() - 3600 * 1000 * 24)
        picker.$emit('pick', date)
      }
    }, {
      text: '一周前',
      onClick(picker) {
        const date = new Date()
        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
        picker.$emit('pick', date)
      }
    }]
  },
  pickerOptions1: {
    disabledDate(time) {
      return time.getTime() < Date.now() - 3600 * 1000 * 24
    },
  },
  pickerOptions2: {
    disabledDate(time) {
      return time.getTime() > Date.now()
    },
    shortcuts: [{
      text: '最近一周',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
        picker.$emit('pick', [start, end])
      }
    }, {
      text: '最近一个月',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
        picker.$emit('pick', [start, end])
      }
    }, {
      text: '最近三个月',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
        picker.$emit('pick', [start, end])
      }
    }]
  },
}

const mutations = {
  getLoginInfo(state, info) {
    state.userInfo = info
    state.agencyId = info.agencyId
  },
  getDistrictData(state, info) {
    state.districtData = info
  },
  //获取企业
  getCompanies(state, info) {
    state.companyInfos = info
    state.colors = []
    info.forEach(item => {
      state.splitMapColors[item.enterpriseNo]=item.color
      state.colors.push(item.color)
      state.companNames.push(item.enterpriseName)
    })
  },
  //获取单位
  getGovAgencyList(state, info) {
    state.govAgencyList = info
  },

  //获取单位
  getBtnMenuIds(state, info) {
    state.btnMenuIds = info
  },
  dialogTop(){
    let bodyHeight = document.querySelector('body').clientHeight
    document.querySelectorAll('.el-dialog').forEach(item => {
      if (item.clientHeight > bodyHeight) {
        item.style = ' top: 0% !important;transform: translate(0%, 0%) !important;'
      }
    })
  },
}
const actions = {
  increment: ({commit}, info) => {
    commit('increment', info)
  },
}

export default new Vuex.Store({
  state,
  actions,
  mutations
})
